package org.boulderfoodrescue.webapp.client.old.datamanager;

import java.util.LinkedList;
import java.util.List;

import org.boulderfoodrescue.webapp.client.old.event.PlaceChangedEvent;
import org.boulderfoodrescue.webapp.client.old.event.PlaceChangedHandler;
import org.boulderfoodrescue.webapp.client.old.event.UserChangedEvent;
import org.boulderfoodrescue.webapp.client.old.event.UserChangedHandler;
import org.boulderfoodrescue.webapp.shared.LoginInfo;
import org.boulderfoodrescue.webapp.shared.Place;
import org.boulderfoodrescue.webapp.shared.UserAccount;

import com.google.gwt.user.client.ui.Widget;

public class DataManager extends Widget{
  private final static DataManager INSTANCE = new DataManager();
  private static LoginInfo loginInfo = null;
  private static List<Place> locations = new LinkedList<Place>();
  private static List<UserAccount> users = new LinkedList<UserAccount>();
  public DataManager(){
    this.addHandler(new PlaceChangedHandler(){
      @Override
      public void onPlaceAdded(PlaceChangedEvent event) {
        locations.add(event.getPlace());
      }
      @Override
      public void onPlaceRemoved(PlaceChangedEvent event) {
        locations.remove(event.getPlace());
      }
      @Override
      public void onPlaceUpdate(PlaceChangedEvent event) {
        // TODO Auto-generated method stub
        
      }}, PlaceChangedEvent.getType());
    
    this.addHandler(new UserChangedHandler(){
      @Override
      public void onUserAdd(UserChangedEvent event) {
        users.add(event.getUser());
      }
      @Override
      public void onUserRemoved(UserChangedEvent event) {
        users.remove(event.getUser());
      }
      @Override
      public void onUserUpdate(UserChangedEvent event) {
        // TODO Auto-generated method stub
      }
        
    }, UserChangedEvent.getType());
  }
  public static LoginInfo getLoginInfo() {
    return loginInfo;
  }
  public static void setLoginInfo(LoginInfo loginInfo) {
    DataManager.loginInfo = loginInfo;
  }
  public static DataManager get() { return INSTANCE; }
  public static List<Place> getLocations() {
    return locations;
  }
  public static List<UserAccount> getUsers() {
    return users;
  }
}
